package com.primaryedu.adapter;

import java.util.ArrayList;
import java.util.List;

import com.bumptech.glide.Glide;
import com.primaryedu.R;
import com.primaryedu.bean.FunctionBean;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

/**
 * 报修详情
 *
 * @author jun.wang
 * @description
 * @data 2016年12月14日
 */
public class RepairDetailsAdapter extends BaseAdapter {

    private Context context;
    LayoutInflater inflater;
//    LoadImage loadImage;
    List<FunctionBean> functionList = new ArrayList<>();

    public RepairDetailsAdapter(Context context, List<FunctionBean> functionList) {
//        loadImage = LoadImage.getInstance();
        this.context = context;
        this.functionList = functionList;
        inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return functionList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (null == convertView) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_repair_details, null);
            viewHolder.image = (ImageView) convertView.findViewById(R.id.image);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

//        viewHolder.image.setTag(functionList.get(position).getPicUrl());
        Glide.with(context)
                .load(functionList.get(position).getPicUrl())
                .placeholder(R.drawable.default_error)
                .error(R.drawable.default_error)
                .centerCrop()
                .crossFade()
                .into(viewHolder.image);
//        loadImage.addTask(functionList.get(position).getPicUrl(), viewHolder.image);
//        loadImage.doTask();

        return convertView;
    }

    class ViewHolder {
        ImageView image;
    }


}
